﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Threading;

namespace BrainTechLLC
{
    public static class Threading
    {
        public static Thread CreateAndRunThread(this ThreadStart ts)
        {
            Thread t = CreateThread(ts); t.Start(); return t;
        }

        public static Thread CreateAndRunThread(this ThreadStart ts, bool isBackground)
        {
            Thread t = CreateThread(ts); t.IsBackground = isBackground; t.Start(); return t;
        }

        public static Thread CreateThread(this ThreadStart ts)
        {
            Thread t = new Thread(ts);
#if NO_SILVERLIGHT
            t.TrySetApartmentState(ApartmentState.MTA);
            t.Priority = ThreadPriority.Normal;
#endif
            t.IsBackground = true;
            return t;
        }
    }
}